using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Manager_Rate_AddRate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        if (!IsPostBack)
            BindData();
    }
    private void BindData()
    {
        clsCommon clsCom = new clsCommon();
        clsWebShop cls = new clsWebShop();
        if (Request.QueryString["RateID"] != "" && Request.QueryString["RateID"] != null)
        {
            PccMsg msg = new PccMsg();
            msg.CreateFirstNode("RateID", Request.QueryString["RateID"]);
            msg.CreateFirstNode("RateDate", "");



            DataTable dt = null;
            dt = cls.Get_RateByCondition(msg.GetXmlStr).Tables[0];
            if (dt.Rows.Count > 0)
            {

                txtUSD.Text = dt.Rows[0]["USD"].ToString();
                lblDate.Text = clsCom.FormatDateTime(dt.Rows[0]["RateDate"].ToString());

            }
        }
        else
        {
            //string DateTime = System.DateTime.Now.ToString("yyyyMMddhhmmss");
            string sDateTime=cls.GetData("select replace(replace(replace(convert(varchar(40), getdate(), 120), ':', ''), ' ', ''), '-', '')").Tables[0].Rows[0][0].ToString();
            lblDate.Text = clsCom.FormatDateTime(sDateTime);
            HidDateTime.Text = sDateTime;
        }
    }
    private void ReturnPage()
    {
        Response.Redirect("Rate.aspx?CodeID=" + Request.QueryString["CodeID"]);
    }
    protected void btnAdd_Catalogue_Click(object sender, EventArgs e)
    {
        PccMsg msg = new PccMsg();

        string RateId = "0";
        if (Request.QueryString["RateID"] != "" && Request.QueryString["RateID"] != null)
            RateId = Request.QueryString["RateID"];
        msg.CreateFirstNode("RateId", RateId);
        msg.CreateFirstNode("RateDate", HidDateTime.Text);
        msg.CreateFirstNode("EditMK", "1");
        msg.CreateFirstNode("USD", txtUSD.Text);
        msg.CreateFirstNode("Status", "N");
        msg.CreateFirstNode("UpdID", Session["AdminUserID"].ToString());


        clsWebShop cls = new clsWebShop();
        cls.Ins_Upd_Rate(msg.GetXmlStr.ToString());
        ReturnPage();
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        ReturnPage();
    }
}
